package GreedyThought;

import java.util.Arrays;
import java.util.Comparator;

// Lettcode 452: https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/
public class findMinArrowShots {
    public int findMinArrowShots(int[][] points) {
        if (points == null) return 0;
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] ints, int[] t1) {
                return ints[1] - t1[1];
            }
        });
        int res = 1;
        int end = points[0][1];
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] <= end) continue;
            res++;
            end = points[i][1];
        }
        return res;
    }
}
